import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GangFightsMeritCellRenderer } from "./cellRenderer/GangFightsMeritCellRenderer";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { FontUtil } from "../../../common/font/FontUtil";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { Cache } from "../../cache/Cache";
import { SGangFightsMyInfo } from "../../../../Message/Public/SGangFightsMyInfo";
import { SGangFightsMyInfoEx } from "../../../../Message/Public/SGangFightsMyInfoEx";
import { SGangFightsAccount } from "../../../../Message/Public/SGangFightsAccount";
import { DateParser } from "../../../common/tools/DateParser";
import { GangFightsMeritData } from "./data/GangFightsMeritData";
import { GTileList } from "../../../../com/mui/controls/GTileList";
//class GangFightsMeritWindow
    
    export  class GangFightsMeritWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(811, 433);
            title = Language.getString(44568);
            titleHeight = 26;
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc7=null;
            super.createChildren();
            this.initDataArray();
            setSize(247, 258);
            ObjCreate.createBg(18, 38, 549, 260, this);
            ObjCreate.createBg(570, 38, 223, 260, this);
            ObjCreate.createBg(18, 301, 775, 120, this);
            ObjCreate.createTextField(Language.getString(44569), 45, 51, 70, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(44570), 160, 51, 110, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(44589), 382, 51, 110, 20, this, GlobalStyle.textFormat6);
            this._tileList = ObjCreate.createTileList(34, 73, 530, 217, this);
            this._tileList.rowHeight = 31;
            this._tileList.columnWidth = 530;
            this._tileList.setStyle("cellRenderer", GangFightsMeritCellRenderer);
            this._tileList.dataProvider = new DataProvider(this._meritDataArray);
            var loc1=GlobalStyle.textFormatGreen;
            loc1.size = 14;
            loc1.bold = true;
            this._tfDate = ObjCreate.createTextField("", 609, 75, 200, 20, this, loc1);
            ObjCreate.createTextField(Language.getString(44571), 604, 117, 90, 20, this);
            ObjCreate.createTextField(Language.getString(44572), 604, 150, 90, 20, this);
            var loc2=GlobalStyle.textFormat6;
            loc2.font = FontUtil.EmbedNumberName;
            loc2.size = 25;
            this._tfLastRank = ObjCreate.createEmbedTextFiled("0", 695, 114, 80, 25, this, loc2);
            this._tfNoRank = ObjCreate.createTextField(Language.getString(42231), 690, 117, 60, 20, this);
            this._tfNoRank.visible = false;
            this._tfLastMerit = ObjCreate.createEmbedTextFiled("0", 695, 147, 80, 25, this, loc2);
            var loc3=ObjCreate.createTextField("", 604, 198, 170, 20, this, GlobalStyle.textFormatGreen);
            loc3.htmlText = Language.getString(44573);
            var loc4;
            (loc4 = GlobalStyle.textFormat1).leading = 7;
            var loc5;
            (loc5 = ObjCreate.createTextField("", 595, 228, 184, 40, this, loc4)).wordWrap = true;
            loc5.multiline = true;
            loc5.text = Language.getString(44574);
            (loc5 = ObjCreate.createTextField("", 595, 268, 184, 20, this, GlobalStyle.textFormatRed)).text = Language.getString(44590);
            this.addChild(new GImageBitmap("GangFightsMeritExcPrize.png", 38, 311));
            var loc6=0;
            while (loc6 < this._prizeItemCodeArray.length) 
            {
                ObjCreate.createBg(37 + 75 * loc6, 340, 64, 64, this);
                (loc7 = new BaseItem()).itemData = new ItemData(int(this._prizeItemCodeArray[loc6]));
                loc7.x = 39 + 75 * loc6;
                loc7.y = 342;
                loc7.width = 60;
                loc7.height = 60;
                this.addChild(loc7);
                ++loc6;
            }
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            var loc1=Cache.instance.gangFights.myInfo;
            var loc2=Cache.instance.gangFights.myInfoEx;
            var loc3=Cache.instance.gangFights.account;
            if (loc1) 
            {
                this.updateInfo(loc1);
            }
            if (loc2) 
            {
                this.updateInfoEx(loc2);
            }
            if (loc3) 
            {
                this.updateAccount(loc3);
            }
            return;
        }

        public updateInfo(arg1: SGangFightsMyInfo): void
        {
            if (arg1.isNewCross) 
            {
                this._tileList.dataProvider = new DataProvider(this._meritDataArrayNewCross);
            }
            else 
            {
                this._tileList.dataProvider = new DataProvider(this._meritDataArray);
            }
            return;
        }

        public updateInfoEx(arg1: SGangFightsMyInfoEx): void
        {
            var loc1=arg1.lastTeamRank > 0;
            this._tfNoRank.visible = !loc1;
            this._tfLastRank.visible = loc1;
            this._tfLastRank.text = arg1.lastTeamRank.toString();
            this._tfLastMerit.text = arg1.lastMerit.toString();
            return;
        }

        public updateAccount(arg1: SGangFightsAccount): void
        {
            this._tfDate.htmlText = DateParser.parse(arg1.monthAccountDt, Language.getStringByParam(44575, arg1.monthAccountIndex));
            return;
        }

        /* internal  */initDataArray(): void
        {
            this._meritDataArray = [];
            this._meritDataArray.push(new GangFightsMeritData("1", "12000", "24000", 14011686));
            this._meritDataArray.push(new GangFightsMeritData("2", "10000", "20000", 14011686));
            this._meritDataArray.push(new GangFightsMeritData("3", "9000", "18000", 14011686));
            this._meritDataArray.push(new GangFightsMeritData("4~10", "5000~8000", "10000~16000", 14011686));
            this._meritDataArray.push(new GangFightsMeritData("11~100", "3000~5000", "6000~10000", 14011687));
            this._meritDataArray.push(new GangFightsMeritData("101~1000", "2000~3000", "4000~6000", 14011688));
            this._meritDataArray.push(new GangFightsMeritData("1001+", "1000~2000", "2000~4000", 14011689));
            this._meritDataArrayNewCross = [];
            this._meritDataArrayNewCross.push(new GangFightsMeritData("1", "3000", "6000", 14011283));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("2", "2500", "5000", 14011284));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("3", "2250", "4500", 14011284));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("4~10", "1250~2000", "2500~4000", 14011285));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("11~100", "750~1250", "1500~2500", 0));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("101~1000", "500~750", "1000~1500", 0));
            this._meritDataArrayNewCross.push(new GangFightsMeritData("1001+", "250~500", "500~1000", 0));
            this._prizeItemCodeArray = [14131400, 14131401, 14131402, 14131403, 14131404, 14131405, 14131406, 14131407, 14131408, 14131409];
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(GangFightsMeritWindow._instance == null);
        }

        public static get instance(): GangFightsMeritWindow
        {
            if (!GangFightsMeritWindow._instance) 
            {
                GangFightsMeritWindow._instance = new GangFightsMeritWindow();
            }
            return GangFightsMeritWindow._instance;
        }

        /* internal */ /* var */_meritDataArray: Array<any>;

        /* internal */ /* var */_meritDataArrayNewCross: Array<any>;

        /* internal */ /* var */_prizeItemCodeArray: Array<any>;

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_tfDate: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLastRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNoRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLastMerit: Object /* flash.text.TextField */;

        /* internal */ static /* var */_instance: GangFightsMeritWindow;
    }
